/*
 *    Copyright 2010-2013 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package com.google.code.jbauble.db;

import java.util.Iterator;
import java.util.List;

import com.google.code.jbauble.db.exception.DataAccessException;

public interface QueryResults<T>  extends Iterable<T> {
	/**
	 * Gets the first entity in the result set.  Obeys the {@link Query} offset value.
	 * 
	 * @return the only instance in the result, or null if the result set is empty.
	 */
	T get() throws DataAccessException;

	/**
	 * <p>Execute the query and get the results (as a {@code List<T>}).</p>
	 * <p>  This method is provided as a convenience;
	 * {@code List<T> results = new ArrayList<T>; for(T ent : fetch()) results.add(ent); return results;}
	 * </p>
	 */
	List<T> asList() throws DataAccessException;
	
	/**
	 * Execute the query and get the results (as a {@code List<Key<T>>})  This method is provided as a convenience;
	 */
	List<Key<T>> asKeyList() throws DataAccessException;	

	/**
	 * <p>Count the total number of values in the result, <strong>ignoring <em>limit</em> and <em>offset</em>.</p>
	 */
	long countAll() throws DataAccessException;
}
